package edu.tms.dao;

import java.util.List;
import java.util.Map;

import edu.tms.bean.ClassDorm;
import edu.tms.crud.JdbcUtil;
import edu.tms.dao.common.CommnonDao;

public class ClassDormDaoImpl implements CommnonDao<ClassDorm>{
	/**
	 * 虞艳
	 * 查询某班级的所有寝室id和寝室名
	 * @param key 班级id
	 * @return	查到的所有寝室id和寝室名字
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<ClassDorm> findAll(long key) throws Exception {
		String sql = "select d.dorm_name,d.dorm_id from t_class_dorm cd,t_dorm d ";
		sql += "where d.dorm_id = cd.dorm_id and cd.class_id = ?";
		return JdbcUtil.query(ClassDorm.class, sql, key);
	}
	/**
	 * 虞艳
	 * 查询班级寝室名称，班级名称，寝室状态，寝室创建时间
	 * @param key
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<ClassDorm> findClassDrom(long key, int pageNo, int pageSize) throws Exception {
		String sql = "SELECT dorm_name,class_name,cd.create_time,class_dorm_state ";
		sql += "FROM t_class_dorm cd,t_dorm d,t_class_info c  WHERE d.dorm_id = cd.dorm_id AND c.class_id=cd.class_id AND cd.class_id =? LIMIT ?,?";
		return JdbcUtil.query(ClassDorm.class, sql, key,(pageNo-1)*pageSize,pageSize);
	}
	
	/**
	 * 虞艳
	 * 查询某班总共有多少宿舍
	 * @param classId
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public long getCount(Integer classId,Integer pageSize) throws Exception{
		String sql = "SELECT  COUNT(*) FROM t_class_dorm cd,t_dorm d,t_class_info c  WHERE d.dorm_id = cd.dorm_id AND c.class_id=cd.class_id AND cd.class_id =?";
		long count =  (long) JdbcUtil.uniqueValue(sql, 1, classId);
		return count%pageSize==0?count/pageSize:count/pageSize+1;
	}
	@Override
	public long save(ClassDorm value) throws Exception {
		return 0;
	}

	@Override
	public int update(ClassDorm value) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int delete(ClassDorm value) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}
	
	
	@Override
	public List<ClassDorm> findAll(int pageNo, int pageSize) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	

	@Override
	public List<ClassDorm> findAll(Object key, int pageNo, int pageSize)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ClassDorm findByKey(Object key) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Map<String, Object>> getMapList() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
